import { EnumSchema } from '@/utils/common/types';
import { PresetColorEnum } from '@/enums/colorEnum';
import { useI18n } from '@/hooks/web/useI18n';

/** 部门机构标记枚举 */
export enum DepartmentFlagEnum {
  /** 当前部门机构标识 */
  CurrentToken = '@CurrentDepartmentId',
  /** 当前及子级部门机构标识 */
  CurrentChildrenToken = '@CurrentChildrenDepartmentId',
  /** 当前及父级部门机构标识 */
  CurrentParentToken = '@CurrentParentDepartmentId',
  /** 当前及父级子级部门机构标识 */
  CurrentParentChildrenToken = '@CurrentParentChildrenDepartmentId',
  /** 子级部门机构标识 */
  ChildrenToken = '@ChildrenDepartmentId',
  /** 父级部门机构标识 */
  ParentToken = '@ParentDepartmentId',
  /** 父级子级部门机构标识 */
  ParentChildrenToken = '@ParentChildrenDepartmentId',
}

/** 部门机构标记实体 */
export class DepartmentFlagEntity {
  /** 部门机构标记 */
  DepartmentFlag: DepartmentFlagEnum;
  /** 显示描述 */
  Display: string;
  /** 颜色 */
  Color?: PresetColorEnum | string;

  constructor(departmentFlag: DepartmentFlagEnum, color?: PresetColorEnum | string) {
    const { t } = useI18n();
    this.DepartmentFlag = departmentFlag;
    this.Color = color;
    switch (departmentFlag) {
      case DepartmentFlagEnum.CurrentToken:
        // this.Display = '@当前部门';
        this.Display = `@${t('enum.departmentFlag.currentToken')}`;
        this.Color = this.Color ? this.Color : PresetColorEnum.Green;
        break;
      case DepartmentFlagEnum.CurrentChildrenToken:
        // this.Display = '@当前及子级部门';
        this.Display = `@${t('enum.departmentFlag.currentChildrenToken')}`;
        this.Color = this.Color ? this.Color : PresetColorEnum.Cyan;
        break;
      case DepartmentFlagEnum.CurrentParentToken:
        // this.Display = '@当前及父级部门';
        this.Display = `@${t('enum.departmentFlag.currentParentToken')}`;
        this.Color = this.Color ? this.Color : PresetColorEnum.Blue;
        break;
      case DepartmentFlagEnum.CurrentParentChildrenToken:
        // this.Display = '@当前及父级子级部门';
        this.Display = `@${t('enum.departmentFlag.currentParentChildrenToken')}`;
        this.Color = this.Color ? this.Color : PresetColorEnum.Geekblue;
        break;
      case DepartmentFlagEnum.ChildrenToken:
        // this.Display = '@子级部门';
        this.Display = `@${t('enum.departmentFlag.childrenToken')}`;
        this.Color = this.Color ? this.Color : PresetColorEnum.Magenta;
        break;
      case DepartmentFlagEnum.ParentToken:
        // this.Display = '@父级部门';
        this.Display = `@${t('enum.departmentFlag.parentToken')}`;
        this.Color = this.Color ? this.Color : PresetColorEnum.Pink;
        break;
      case DepartmentFlagEnum.ParentChildrenToken:
        // this.Display = '@父级子级部门';
        this.Display = `@${t('enum.departmentFlag.parentChildrenToken')}`;
        this.Color = this.Color ? this.Color : PresetColorEnum.Red;
        break;
    }
  }
}

//#region 获取部门机构标记枚举架构
/**
 * 获取部门机构标记枚举架构
 */
export function getDepartmentFlagEnumSchema(enableTag = true): EnumSchema[] {
  const enumSchema: EnumSchema[] = [];
  const entities: DepartmentFlagEntity[] = [
    new DepartmentFlagEntity(DepartmentFlagEnum.CurrentToken),
    new DepartmentFlagEntity(DepartmentFlagEnum.CurrentChildrenToken),
    new DepartmentFlagEntity(DepartmentFlagEnum.CurrentParentToken),
    new DepartmentFlagEntity(DepartmentFlagEnum.CurrentParentChildrenToken),
    new DepartmentFlagEntity(DepartmentFlagEnum.ChildrenToken),
    new DepartmentFlagEntity(DepartmentFlagEnum.ParentToken),
    new DepartmentFlagEntity(DepartmentFlagEnum.ParentChildrenToken),
  ];
  entities.forEach((item) => {
    enumSchema.push({
      key: item.DepartmentFlag as string,
      label: item.Display,
      value: item.DepartmentFlag as string,
      tag: enableTag,
      tagColor: item.Color,
    });
  });
  return enumSchema;
}
//#endregion
